<template>
  <el-dialog
      :title="!dataForm.jdId ? '新增' : '修改'"
      :close-on-click-modal="false"
      :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()"
             label-width="80px">
<el-form-item label="病历编号" prop="blId">
  <el-input v-model="dataForm.blId" placeholder="病历编号"></el-input>

</el-form-item>
<el-form-item label="就诊时间" prop="jdDate">
  <el-input v-model="dataForm.jdDate" placeholder="就诊时间"></el-input>

</el-form-item>
<el-form-item label="就诊科室" prop="jdKs">
  <el-input v-model="dataForm.jdKs" placeholder="就诊科室"></el-input>

</el-form-item>
<el-form-item label="主诉" prop="jdChief">
  <el-input v-model="dataForm.jdChief" placeholder="主诉"></el-input>

</el-form-item>
<el-form-item label="现病史" prop="jdNow">
  <el-input v-model="dataForm.jdNow" placeholder="现病史"></el-input>

</el-form-item>
<el-form-item label="既往史" prop="jdBefore">
  <el-input v-model="dataForm.jdBefore" placeholder="既往史"></el-input>

</el-form-item>
<el-form-item label="体温" prop="jdTem">
  <el-input v-model="dataForm.jdTem" placeholder="体温"></el-input>

</el-form-item>
<el-form-item label="脉搏" prop="jdPlus">
  <el-input v-model="dataForm.jdPlus" placeholder="脉搏"></el-input>

</el-form-item>
<el-form-item label="呼吸" prop="jdBreath">
  <el-input v-model="dataForm.jdBreath" placeholder="呼吸"></el-input>

</el-form-item>
<el-form-item label="血压" prop="jdPress">
  <el-input v-model="dataForm.jdPress" placeholder="血压"></el-input>

</el-form-item>
<el-form-item label="检查资料" prop="jdCheck">
  <el-input v-model="dataForm.jdCheck" placeholder="检查资料"></el-input>

</el-form-item>
<el-form-item label="初步诊断" prop="jdDiagnosis">
  <el-input v-model="dataForm.jdDiagnosis" placeholder="初步诊断"></el-input>

</el-form-item>
<el-form-item label="处理和建议" prop="jdDeal">
  <el-input v-model="dataForm.jdDeal" placeholder="处理和建议"></el-input>

</el-form-item>
<el-form-item label="处理人姓名" prop="jdYsName">
  <el-input v-model="dataForm.jdYsName" placeholder="处理人姓名"></el-input>

</el-form-item>
<el-form-item label="处理人编号" prop="jdYsId">
  <el-input v-model="dataForm.jdYsId" placeholder="处理人编号"></el-input>

</el-form-item>
<el-form-item label="电子病历电子图片" prop="jdImg">
  <el-input v-model="dataForm.jdImg" placeholder="电子病历电子图片"></el-input>

</el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          jdId: 0,
          blId: '',
          jdDate: '',
          jdKs: '',
          jdChief: '',
          jdNow: '',
          jdBefore: '',
          jdTem: '',
          jdPlus: '',
          jdBreath: '',
          jdPress: '',
          jdCheck: '',
          jdDiagnosis: '',
          jdDeal: '',
          jdYsName: '',
          jdYsId: '',
          jdImg: ''
        },
        dataRule: {
          blId: [
            { required: true, message: '病历编号不能为空', trigger: 'blur' }
          ],
          jdDate: [
            { required: true, message: '就诊时间不能为空', trigger: 'blur' }
          ],
          jdKs: [
            { required: true, message: '就诊科室不能为空', trigger: 'blur' }
          ],
          jdChief: [
            { required: true, message: '主诉不能为空', trigger: 'blur' }
          ],
          jdNow: [
            { required: true, message: '现病史不能为空', trigger: 'blur' }
          ],
          jdBefore: [
            { required: true, message: '既往史不能为空', trigger: 'blur' }
          ],
          jdTem: [
            { required: true, message: '体温不能为空', trigger: 'blur' }
          ],
          jdPlus: [
            { required: true, message: '脉搏不能为空', trigger: 'blur' }
          ],
          jdBreath: [
            { required: true, message: '呼吸不能为空', trigger: 'blur' }
          ],
          jdPress: [
            { required: true, message: '血压不能为空', trigger: 'blur' }
          ],
          jdCheck: [
            { required: true, message: '检查资料不能为空', trigger: 'blur' }
          ],
          jdDiagnosis: [
            { required: true, message: '初步诊断不能为空', trigger: 'blur' }
          ],
          jdDeal: [
            { required: true, message: '处理和建议不能为空', trigger: 'blur' }
          ],
          jdYsName: [
            { required: true, message: '处理人姓名不能为空', trigger: 'blur' }
          ],
          jdYsId: [
            { required: true, message: '处理人编号不能为空', trigger: 'blur' }
          ],
          jdImg: [
            { required: true, message: '电子病历电子图片不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.jdId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.jdId) {
            this.$http({
              url: this.$http.adornUrl(`/hospital/jd/info/${this.dataForm.jdId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.blId = data.jd.blId
                this.dataForm.jdDate = data.jd.jdDate
                this.dataForm.jdKs = data.jd.jdKs
                this.dataForm.jdChief = data.jd.jdChief
                this.dataForm.jdNow = data.jd.jdNow
                this.dataForm.jdBefore = data.jd.jdBefore
                this.dataForm.jdTem = data.jd.jdTem
                this.dataForm.jdPlus = data.jd.jdPlus
                this.dataForm.jdBreath = data.jd.jdBreath
                this.dataForm.jdPress = data.jd.jdPress
                this.dataForm.jdCheck = data.jd.jdCheck
                this.dataForm.jdDiagnosis = data.jd.jdDiagnosis
                this.dataForm.jdDeal = data.jd.jdDeal
                this.dataForm.jdYsName = data.jd.jdYsName
                this.dataForm.jdYsId = data.jd.jdYsId
                this.dataForm.jdImg = data.jd.jdImg
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/hospital/jd/${!this.dataForm.jdId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'jdId': this.dataForm.jdId || undefined,
                'blId': this.dataForm.blId,
                'jdDate': this.dataForm.jdDate,
                'jdKs': this.dataForm.jdKs,
                'jdChief': this.dataForm.jdChief,
                'jdNow': this.dataForm.jdNow,
                'jdBefore': this.dataForm.jdBefore,
                'jdTem': this.dataForm.jdTem,
                'jdPlus': this.dataForm.jdPlus,
                'jdBreath': this.dataForm.jdBreath,
                'jdPress': this.dataForm.jdPress,
                'jdCheck': this.dataForm.jdCheck,
                'jdDiagnosis': this.dataForm.jdDiagnosis,
                'jdDeal': this.dataForm.jdDeal,
                'jdYsName': this.dataForm.jdYsName,
                'jdYsId': this.dataForm.jdYsId,
                'jdImg': this.dataForm.jdImg
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
